home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / xarc_1_1.lha / xarc
Text File  |  1997-07-12  |  3KB  |  123 lines

  1. /* :ts=2
  2.  *
  3.  *  XArc.rexx
  4.  *
  5.  *  Unpack archive file of any type based on file contents.
  6.  *
  7.  *  Currently supported: ZOO, LHA, LZH, ARC, ZIP, ARJ
  8.  *
  9.  *  Based on unpack.rexx Revision 1.1  90/02/02  21:59:51  jh
  10.  *
  11.  */
  12.  
  13. options failat 10
  14.  
  15. signal on halt
  16. signal on ioerr
  17. signal on break_c
  18.  
  19. CSI     = '9b'x
  20. OFF     = CSI'0m'
  21. BO      = CSI'37m'
  22.  
  23. packer.       = ""
  24. cmd.          = ""
  25.  
  26. packer.arc                      = "pkxarc"
  27. cmd.x.arc                       = "-x"
  28. cmd.v.arc                       = "-v"
  29. cmd.a.arc                       = ""
  30.  
  31. packer.zoo                      = "Zoo"
  32. cmd.x.zoo                       = "e//"
  33. cmd.v.zoo                       = "v"
  34. cmd.a.zoo                       = "a"
  35.  
  36. packer.lharc            = "LHA -a -x -m"
  37. /*packer.lharc          = "lz -a -x -m"*/
  38. cmd.x.lharc                     = "e"
  39. cmd.v.lharc                     = "v"
  40. cmd.a.lharc                     = "a"
  41.  
  42. packer.zip                      = "unzip"
  43. cmd.x.zip                       = " "
  44. cmd.v.zip                       = "-v"
  45. cmd.a.zip                       = ""
  46.  
  47. packer.arj                      = "unarj"
  48. cmd.x.arj                       = "x"
  49. cmd.v.arj                       = "l"
  50. cmd.a.arj                       = ""
  51.  
  52. ext = "ZOO LZH ARC ZIP ARJ"
  53.  
  54. if arg() = 0 | arg(1) = '?' then call usage
  55.  
  56. parse upper arg option infiles
  57.  
  58.  
  59. select
  60.   when option="V" then com=v
  61.   when option="E" then com=x
  62.   when option="X" then com=x
  63.   when option="A" then com=a
  64.   otherwise call usage
  65. end
  66.  
  67. parse var infiles file infiles
  68.  
  69. ofile = file
  70. do while ~exists(file)
  71.   parse var ext this ext
  72.   if this="" then do
  73.     say BO"Can't find" ofile OFF
  74.     exit 20
  75.   end
  76.   file = ofile"."this
  77. end
  78.  
  79. /* ------- Get type from file content ------- */
  80. if ~open('in', file, 'R') then do
  81.   say BO"Can't open" file OFF
  82.   exit 20
  83. end
  84. buff = readch('in', 8)
  85. call close ('in')
  86.  
  87. select
  88.   when left(buff, 4)      == 'ZOO '                     then type = zoo
  89.   when substr(buff, 3, 3) == '-lh'                      then type = lharc
  90.   when left(buff, 1)      == '1A'x                      then type = arc
  91.   when left(buff, 2)      == 'PK'                       then type = zip
  92.         when left(buff, 2)                      == '60'x||'ea'x then type = arj
  93.   otherwise do
  94.     say BO"Cannot handle" file"!"OFF
  95.     exit 20
  96.   end
  97. end
  98.  
  99. say BO"Processing" file "type" type "..."OFF
  100. if cmd.com.type=="" then do
  101.         say BO"Can't do that"OFF
  102.         exit 20
  103. end
  104.  
  105. Address Command packer.type cmd.com.type file infiles
  106. exit RC
  107.  
  108. /* ----------------------------------------------------------------------- */
  109. * Error Handling */
  110. halt:
  111. ioerr:
  112. break_c:
  113. exit 10
  114.  
  115. /* ----------------------------------------------------------------------- */
  116. usage:
  117.         say "Usage: XArc command filename [filename..]"
  118.         say
  119.         say "    E,X   extract files"
  120.         say "    V     list archive contents"
  121.         say "    A     add files to archive"
  122.         exit 0
  123.